package com.share.lottery.activity.grid;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

import com.share.lottery.R;
import com.share.lottery.base.BaseActivity;
import com.share.lottery.base.Constants;
import com.share.lottery.model.CaiboRmdBean;
import com.share.lottery.model.UserInfo;
import com.share.lottery.utils.StringUtil;


/**
 * @author py
 *写评论
 */
public class ZjWritePlActivity extends BaseActivity {
	
	private EditText edWrite;
	private String planId = "";
	private String loginId;
	protected void onCreate(Bundle savedInstanceState) {
	
		super.onCreate(savedInstanceState);
		setContentView(R.layout.write_pl);
		init();
	}
	
	public void findView() {
		edWrite = (EditText) findViewById(R.id.ed_write);

	}

	
	public void getData() {
		Bundle bundle = getIntent().getExtras();
		
		if (bundle != null) {
			CaiboRmdBean bean = (CaiboRmdBean) bundle.get("cbbean");
			planId = bean.getPlanId();
			}
		
		UserInfo user = Constants.getUserBean();
		if (user != null && user.getUserId() != null) {
			loginId = user.getUserId();
		}

	}

	private TextView titleTv;
	public void initTitle() {
		ImageButton titleLeftImg = (ImageButton) findViewById(R.id.title_left_img);
		TextView titleRightImg = (TextView) findViewById(R.id.title_right_tv);
		titleTv = (TextView) findViewById(R.id.title_tv_center);

		titleLeftImg.setImageResource(R.drawable.back);
		titleTv.setText("方案评论");
		titleRightImg.setText("发布");
		titleRightImg.setVisibility(View.VISIBLE);
		titleRightImg.setOnClickListener(new OnClickListener() {
			
		
			public void onClick(View view) {
				String s = edWrite.getText().toString();
				if (!StringUtil.isNullOrEmpty(s)) {
				
				//	CaiboRmdController.getInstance().caibaoRmdComment_post(handler, planId, loginId, s);
					Log.i("test","当前用户id="+loginId);
					
				}else {
					showShortToast("请先输入评论内容");
				}
			}
		});
		titleLeftImg.setOnClickListener(new OnClickListener() {
			

			public void onClick(View arg0) {
				setEnd();
				
			}
		});

	}
	private void setEnd(){
		finish();
	}
	private void doMessage(Message msg) {
		switch (msg.arg1) {
		case Constants.HTTP_OK://请求成功
			
			String s = (String) msg.obj;
			showShortToast(s);
			
			break;
		case Constants.HTTP_ERROR://请求错误
			String serror = (String) msg.obj;
			showShortToast(serror);
			break;
		case Constants.HTTP_ERROR_PASER://数据解析错误
			showShortToast("数据解析错误");
			break;
		case Constants.HTTP_ERROR_NET://网络错误

			showShortToast("网络错误，请检查网络");
			break;

		default:
			break;
		}
		setEnd();

	}

	Handler handler = new Handler(){
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case Constants.CAIBO_RMD_RUNNING:
				doMessage(msg);
				break;

			default:
				break;
			}

		}


	};
	@Override
	public void setData() {
	
	}

	@Override
	public void setonCliker() {
	

	}

}
